package com.gqzmy.springboot3.controller;

import com.github.pagehelper.PageInfo;
import com.gqzmy.springboot3.entity.Role;
import com.gqzmy.springboot3.service.RoleService;
import com.gqzmy.springboot3.vo.RoleQuery;
import jakarta.annotation.Resource;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

/**
 * @author 周小哥  gqzmy@163.com 2023/4/20 17:12
 */

@RequestMapping("/role")
@RestController
public class RoleController {

    @Resource
    private RoleService roleService;

    @PostMapping("/insert")
    public ResponseEntity<Role> insertRole(@RequestBody Role role) {
        return new ResponseEntity<>(roleService.insertRole(role), HttpStatus.OK);
    }

    @DeleteMapping("/{id}")
    public ResponseEntity<Boolean> deleteById(@PathVariable("id") String id) {
        return new ResponseEntity<>(roleService.deleteById(id), HttpStatus.OK);
    }

    @GetMapping("/{id}")
    public ResponseEntity<Role> getById(@PathVariable("id") String id) {
        return new ResponseEntity<>(roleService.getById(id), HttpStatus.OK);
    }

    @PostMapping("/get")
    public ResponseEntity<PageInfo<Role>> getRolePageInfo(@RequestBody RoleQuery roleQuery) {
        PageInfo<Role> rolePageInfo = roleService.getRolePageInfo(roleQuery);
        return new ResponseEntity<>(rolePageInfo, HttpStatus.OK);
    }
}
